package org.bing.flex.helper {
    import flash.external.ExternalInterface;

    public class PageUrlHelper {
        private static var url:String;

        public static function getPageUrl():String {
            if (url != null) {
                return url;
            }
            ExternalInterface.call("eval", "function getPageURL(){return '' + window.location;}");
            url=ExternalInterface.call("getPageURL");
            return url;
        }

        public static function getUrlParameter(name:String):String {
            var url:String=getPageUrl();
            var key:String=name + "=";
            var begin:int=url.indexOf(key);
            var end:int=url.indexOf("&", begin);
            if (begin != -1 && end != -1) {
                return url.substring(begin + key.length, end);
            } else if (begin != -1) {
                return url.substring(begin + key.length, url.length);
            }

            return null;
        }
    }
}